<div class="btn-group">
    <button type="button" class="btn dropdown-toggle" data-toggle="dropdown"
            ng-class="{
                        'btn-warning': currentBuildFilterResource,
                        'btn-default': !currentBuildFilterResource
                        }">
        Filter<span ng-show="currentBuildFilterResource.name">: {{currentBuildFilterResource.name}}</span>
        <span class="caret"></span>
    </button>
    <ul class="dropdown-menu ot-buildfilter-list" role="menu">
        <!-- Predefined filters -->
        <li role="presentation" class="dropdown-header">Predefined filters:</li>
        <li ng-repeat="buildFilterForm in buildFilterForms.resources | filter:{predefined:true}">
            <a>
                <!-- Filter selection -->
                <span class="fa fa-check" ng-show="currentBuildFilterResource.name == buildFilterForm.typeName"></span>
                <!-- Filter name -->
                <span ng-click="buildFilterNew(buildFilterForm)">
                    <span class="ot-buildfilter-remote"
                          title="This filter does not need any configuration">
                        {{buildFilterForm.typeName}}
                        <span class="fa fa-star"></span>
                    </span>
                </span>
            </a>
        </li>
        <!-- Existing filters -->
        <li role="presentation" class="dropdown-header" ng-if="buildFilterResources">Existing filters:</li>
        <li ng-repeat="buildFilterResource in buildFilterResources">
            <a>
                <!-- Filter selection -->
                <span class="fa fa-check" ng-show="currentBuildFilterResource.name == buildFilterResource.name"></span>
                <!-- Filter name -->
                <span ng-click="buildFilterApply(buildFilterResource)"
                      ng-class="{
                        'ot-buildfilter-local': !buildFilterResource._update,
                        'ot-buildfilter-remote': buildFilterResource._update,
                        'ot-buildfilter-invalid': !!buildFilterResource.error
                      }"
                      title="{{getBuildFilterTooltip(buildFilterResource)}}"
                >
                    {{buildFilterResource.name}}
                    <span ng-if="!buildFilterResource._update"> (local)</span>
                </span>
                <!-- Saving only if local and logged -->
                <span class="fa fa-save ot-command" ng-if="!buildFilterResource._update && logged()"
                      title="Save this filter in your preferences"
                      ng-click="buildFilterSave(buildFilterResource)"></span>
                <!-- Sharing -->
                <span class="fa fa-share ot-command" ng-if="!buildFilterResource.shared && branch._buildFilterShare"
                      title="Saves this filter and makes it available for all users in the branch"
                      ng-click="buildFilterShare(buildFilterResource)"></span>
                <!-- Saved filter -->
                <span class="fa fa-user ot-command" ng-if="buildFilterResource._update && !buildFilterResource.shared"
                      title="This filter has been saved in your preferences"
                      ng-click="buildFilterApply(buildFilterResource)"></span>
                <!-- Shared filter -->
                <span class="fa fa-group ot-command" ng-if="buildFilterResource.shared"
                      title="This filter has been shared for use in the branch."
                      ng-click="buildFilterApply(buildFilterResource)"></span>
                <!-- Edition -->
                <span class="ot-command-update ot-command"
                      title="Edit this filter"
                      ng-if="!buildFilterResource.shared || branch._buildFilterShare"
                      ng-click="buildFilterEdit(buildFilterResource)"></span>
                <!-- Deletion always available, but for the shared filters -->
                <span class="ot-command-delete ot-command"
                      title="Delete this filter"
                      ng-if="!buildFilterResource.shared || branch._buildFilterShare"
                      ng-click="buildFilterRemove(buildFilterResource)"></span>
            </a>
        </li>
        <li class="divider" ng-if="buildFilterResources"></li>
        <li ng-if="currentBuildFilterResource && !currentBuildFilterResource.name">
            <a ng-click="buildFilterEdit(currentBuildFilterResource)">
                <span class="fa fa-pencil"></span>
                Edit filter
            </a>
        </li>
        <li ng-if="currentBuildFilterResource">
            <a ng-click="buildFilterErase()">
                <span class="fa fa-eraser"></span>
                Reset filter
            </a>
        </li>
        <li ng-if="currentBuildFilterResource">
            <a ng-click="buildFilterLink()">
                <span class="fa fa-link"></span>
                Permalink
            </a>
        </li>
        <li class="divider" ng-if="currentBuildFilterResource"></li>
        <!-- New filters -->
        <li role="presentation" class="dropdown-header">New filter:</li>
        <li ng-repeat="buildFilterForm in buildFilterForms.resources | filter:{predefined:false}">
            <a>
                <span ng-click="buildFilterNew(buildFilterForm)">
                    <span ng-if="!buildFilterForm.predefined">{{buildFilterForm.typeName}}...</span>
                </span>
            </a>
        </li>
    </ul>
</div>